package com.shou.lifecollege.framework.Security.handle;

import com.alibaba.fastjson.JSON;
import com.shou.lifecollege.framework.Common.constant.Constants;
import com.shou.lifecollege.framework.Common.result.RequestResult;
import com.shou.lifecollege.framework.Common.util.ServletUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录成功处理类
 * @Author: luotian
 * @Date: 2022/11/24 17:21
 */
@Component
public class CustomAuthenticationSuccessImpl implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        ServletUtils.renderString(response, JSON.toJSONString(RequestResult.success(Constants.LOGIN_SUCCESS)));
    }
}
